package com.mediacloud.app.newsmodule.view;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ListView;

import com.mediacloud.app.assembly.util.Utility;
import com.mediacloud.app.model.adaptor.BaseAdaptor;
import com.mediacloud.app.newsmodule.R;

/**
 * 音频下面的那个列表
 * @author x
 *
 * @param <T>
 */
public class AudioBottomDialog<T> extends FrameLayout
{
	public static final int StreamMode=1;
	public static final int AudioListMode=2;

	public int mode=StreamMode;
	protected View contentView;
	protected Context mContext;
	protected OnItemClickListener listener;
	protected BaseAdaptor<T> adaptor;
    public ListView audio_bottom_list;
	public AudioBottomDialog(Context context)
	{
		super(context);
		mContext=context;
		contentView=LayoutInflater.from(mContext).inflate(R.layout.aappfactory_aduio_stream, null);
		addView(contentView);
		contentView.setOnTouchListener(new OnTouchListener() {
			
			@Override
			public boolean onTouch(View v, MotionEvent event) {
				boolean b= contentView.onTouchEvent(event);
				dismiss();
				return true;
			}
		});
		audio_bottom_list=Utility.findViewById(contentView, R.id.audio_bottom_list);
//		audio_bottom_list.setPullLoadEnable(false);
//		audio_bottom_list.setPullRefreshEnable(false);
		audio_bottom_list.setHeaderDividersEnabled(false);
		audio_bottom_list.setFooterDividersEnabled(false);
		audio_bottom_list.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				dismiss();
				if(listener!=null)
				{
					listener.onItemClick(parent, view, position, id);
				}
			}
		});
        ImageView imageViewClose = Utility.findViewById(contentView, R.id.image_close);
        imageViewClose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
	}

	private void dismiss() {
		if(getParent()!=null)
		{
			((ViewGroup)getParent()).removeView(this);
		}
	}

	public void setItemClickListener(OnItemClickListener listener)
	{
		this.listener=listener;
	}
	
	public void setListAdaptor(BaseAdaptor<T> adaptor)
	{
		this.adaptor=adaptor;
		audio_bottom_list.setAdapter(this.adaptor);
	}
}